package network;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class Configuration {
    private static final String configurationName = "config.prop";
    private static final String addressFieldName = "address", portFieldName = "port",
            historyFieldName = "historyPath", errorFieldName = "errorFile", authenticationFieldName = "authenticationFile",
            historyDelayFieldName = "historyDelay";

    private static String address = "localhost";
    private static int port = 888, historyDelay =2;
    private static String historyFilePath = "C:\\Users\\Student\\Desktop\\";
    private static String errorFileName = "C:\\Users\\Student\\Desktop\\error_file.log";
    private static String authenticationFileName = "C:\\Users\\Student\\Desktop\\auth_file.log";

    public static void loadConfiguration() {
        try {
            FileInputStream inputStream = new FileInputStream(configurationName);
            Properties properties = new Properties();
            properties.load(inputStream);
            address = properties.getProperty(addressFieldName);
            port = Integer.parseInt(properties.getProperty(portFieldName));
            historyFilePath = properties.getProperty(historyFieldName);
            errorFileName = properties.getProperty(errorFieldName);
            authenticationFileName = properties.getProperty(authenticationFieldName);
            historyDelay = Integer.parseInt(properties.getProperty(historyDelayFieldName));
        } catch (IOException e) {
            e.printStackTrace();
            System.err.println("Couldn't load configuration file");
        }
    }

    public static int getHistoryDelay() {
        return historyDelay;
    }

    public static String getHistoryFilePath() {
        return historyFilePath;
    }

    public static String getErrorFileName() {
        return errorFileName;
    }

    public static String getAuthenticationFileName() {
        return authenticationFileName;
    }

    public static String getAddress() {
        return address;
    }

    public static int getPort() {
        return port;
    }
}
